<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人和人律师事务所管理系统v1.0-现有资产管理</title>

<!-- 控件布局方式  -->
<style type="text/css" media="all">
.allow-float {
	clear: none !important;
}  /* 允许该元素浮动 */
.stop-float {
	clear: both !important;
}  /* 阻止该元素浮动 */
.float-left {
	float: left;
	padding-left: 40px
} /*浮动到左边*/
</style>

<script type="text/javascript">
Ext.onReady(function(){

	//查询框
	var searchExistFixAssetPan=new Ext.form.FormPanel({
			labelAlign:'right',
			title:'现有资产查询',
			labelSeparator :'：',//分隔符
			labelWidth : 100,//标签宽度
			bodyStyle:'padding:5',//表单边距
			frame : true,
			collapsible: true,
			height:100,
			width:window.screen.width-220,
			applyTo :'searchExistAssetWin',

			items:[
				new Ext.form.DateField({
					fieldLabel : '买进时间介于',
					format:'Y-m-d',
					id : 'sBuyTime',
					name : 'sBuyTime',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.DateField({
					fieldLabel : '与',
					format:'Y-m-d',
					labelWidth:50,
					id : 'eBuyTime',
					name : 'eBuyTime',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.TextField({
					fieldLabel : '资产名',
					id : 'assetName',
					name : 'assetName',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.Button({
					text : '开始查询',
					iconCls:'search',
					cls:'float-left',//向左浮动
					handler : submitMsg
				})
			]
	})



		//查询处理函数
	function submitMsg(){
		//获得查询条件
		var sBuyTime=Ext.getCmp("sBuyTime").value;
		var eBuyTime=Ext.getCmp("eBuyTime").value;
		var assetName=Ext.getCmp("assetName").getValue();
		//判断是否输入了年份
		if(sBuyTime==""&&assetName=="")
		{
		Ext.Msg.alert('信息', '请输入查询条件再提交!');
		return;
		}
		 store = new Ext.data.JsonStore({
	url:"SearchExistAsset.jsj?sBuyTime="+sBuyTime+"&eBuyTime="+eBuyTime+"&assetName="+assetName,
	totalProperty: 'totalCount',
    root: 'result',
	fields:["fixedassetsid","buytime","goodsname","purchasenumber","goodsmoney","wipeoutnumber","goodsbrief"]
});
		store.reload({
			params:{
				start:0,
				limit:5
				}
			});
		var colModel = new Ext.grid.ColumnModel([//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "固定资产ID",width: 100,  dataIndex: 'fixedassetsid', sortable: true},
				{header: "买进时间", width: 100,dataIndex: 'buytime', sortable: true},
				{header: "物品名",width: 150, dataIndex: 'goodsname', sortable: true},
				{header: "购买数量",width: 100, dataIndex: 'purchasenumber', sortable: true},
				{header: "金额",width: 100, dataIndex: 'goodsmoney', sortable: true},
				{header: "报销数量",width: 100, dataIndex: 'wipeoutnumber', sortable: true},
				{header: "备注",width: 200, dataIndex: 'goodsbrief', sortable: true}
				]);
				pagebar.bind(store);
				grid.reconfigure(store,colModel);
		grid.getView().refresh(true);
	}


	 //存储器
	var store = new Ext.data.JsonStore({
	url:"FixedAssetRequest.jsj",
	totalProperty: 'totalCount',
	root: 'result',
	fields:["fixedassetsid","buytime","goodsname","purchasenumber","goodsmoney","wipeoutnumber","goodsbrief"]
});
		store.load({
			params:{
				start:0,
				limit:5
				}
			});

	//获得用户权限
		var buttonDisabled=true;
	<%
	if((java.lang.Integer)session.getAttribute("popedomLevel")==1){
		%>
		buttonDisabled=false;
	<%
	}
	%>

		//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '发票详细信息'},
			'-',
			{
			text:'查看资金情况',
			iconCls:'search',
			handler:function(btn,pressed){
			lookGoodsMoney();
			}
			},
			'-',
			{
			text:'新添设备',
			iconCls:'add',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			addAssetInfo();
			}
			},
			'-',
			{
			text:'修改',
			iconCls:'option',
			handler:function(btn,pressed){
			modifyAssetInfo();
			}
			},
			'-',
			{
			text:'报销',
			iconCls:'remove',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			wipeOutAssetInfo();
			}
			}
		]);



				//修改固定资产面板
		var modifyAssetPanel;
		//修改固定资产窗口
		var modifyAssetWin;
		//修改固定资产函数
		function modifyAssetInfo(){
				//获取要修改的一条记录
			var record=grid.getSelectionModel().getSelected();
			//如果没有选择用户
			if(!record){
				Ext.MessageBox.alert("修改操作","请选择要修改的一项！");
			}else{
				//修改固定资产窗口
				modifyAssetWin=new Ext.Window({
					width:500,
					height:250,
					closeAction:'hide',
					layout:'fit',
					plain:true,
					title:'修改固定资产信息窗口',
					items:modifyAssetPanel
				});
				//显示窗口
				modifyAssetWin.show();
				//加载原数据
 				 Ext.getCmp("mAssetId").setValue(record.get("fixedassetsid"));
       			 Ext.getCmp("mAssetTime").setValue(record.get("buytime"));
       			 Ext.getCmp("mAssetName").setValue(record.get("goodsname"));
       			 Ext.getCmp("mAssetPurNumber").setValue(record.get("purchasenumber"));
       			 Ext.getCmp("mAssetMoney").setValue(record.get("goodsmoney"));
       	    	 Ext.getCmp("mAssetWipeNumb").setValue(record.get("wipeoutnumber"));
				 Ext.getCmp("mAssetBrief").setValue(record.get("goodsbrief"));
			}
		}

		//修改固定资产信息面板
		 modifyAssetPanel=new Ext.form.FormPanel({
		 		labelAlign:'right',
		 		buttonAlign:'center',
		 		closeAction:true,
		 		labelWidth:100,
		 		frame:true,
		 		bodyStyle:'padding:5px 5px 0',
		 		waitMsgTraget:true,
		 		defaults:{
		 			width:250
		 		},
		 		defaultType:'textfield',
		 		items:[
		 	{
		 		xtype:'hidden',
	            name :'mAssetId',
	            id :'mAssetId'
		    },
		    {
	            fieldLabel : '买进时间',
	            name :'mAssetTime',
	            id :'mAssetTime',
	            allowBlank :false
		    },
		    {
	            fieldLabel : '物品名',
	            name :'mAssetName',
	            id :'mAssetName',
	            allowBlank :false
	        },
	        {
	            fieldLabel : '购买数量',
	            name :'mAssetPurNumber',
	            id :'mAssetPurNumber',
	            allowBlank :false
	        },
	        {
	            fieldLabel :'金额',
				id :'mAssetMoney',
				name :'mAssetMoney',
				allowBlank :false
	        },
	        {
	            fieldLabel :'报销数量',
				id :'mAssetWipeNumb',
				name :'mAssetWipeNumb',
				allowBlank :false
	        },
	        {
	            fieldLabel :'备注',
				id :'mAssetBrief',
				name :'mAssetBrief',
				allowBlank :false
	        }
		 		],

		 buttons : [ {
            text : '修改',
            disabled : false,
            handler : function() {
                if (modifyAssetPanel.form.isValid()) {
                    modifyAssetPanel.form.submit( {
                        url : 'ModifyAssetInfo.jsj',
                        success : function(from, action) {
                        Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyAssetWin.hide();
                        },
                        failure : function(form, action) {
                           Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyAssetWin.hide();
                        },
                        waitMsg : '正在保存数据，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        }, {
            text : '取消',
            handler : function() {
                modifyAssetWin.hide();
            }
        }]
		 })



			//添加固定资产窗口
	var addFixedAssetWin;
	//添加固定资产面板
	var addFixedAssetForm;
	function addAssetInfo(){
		//添加设备窗口
		addFixedAssetWin=new Ext.Window({
			title:'增加设备',
			width:400,
			height:250,
			layout:'fit',
			closeAction:'hide',
			resizable:'false',
			//内嵌面板
			items:addFixedAssetForm
		});
		//显示窗口
		addFixedAssetWin.show();
	}

	//添加设备记录面板
	addFixedAssetForm=new Ext.form.FormPanel({
	labelAlign:'right',
	buttonAlign:'center',
	frame:true,
	labelWidth:100,
	defaults:{
		width:200
	},
	//控件
	items:[
	{
		xtype:'datefield',
		fieldLabel:'时间',
		format:'Y-m-d',
		name:'fixedAssetTime',
		allowBlank:false
	},
	{
		xtype:'textfield',
		fieldLabel:'物品名',
		name:'fixedAssetName',
		allowBlank:false
	},
	{
		xtype:'textfield',
		fieldLabel:'购买数量',
		name:'fixedAssetNumb',
		allowBlank:false
	},
	{
		xtype:'textfield',
		fieldLabel:'总金额',
		name:'fixedAssetMoney',
		allowBlank:false
	},
	{
		xtype:'textarea',
		fieldLabel:'备注',
		name:'fixedAssetRemark',
		allowBlank:false
	}
	],
	buttons:[{
	text:'确认',
	handler:function(){
		//判断是否输入了数据
		if(addFixedAssetForm.form.isValid()){
			addFixedAssetForm.form.submit({
			url:'AddFixedAssetInfo.jsj',
				success:function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addFixedAssetWin.hide();
				},
				failure: function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addFixedAssetWin.hide();
				},
				waitMsg:'正在保存数据，稍后...'
			})
		}else{
			Ext.Msg.alert('提示','请填写完成再提交！');
		}
	}
	},{
		text:'取消',
		handler:function(){
			addFixedAssetWin.hide();
		}
	}]
	})


	//报销窗口
	var wipeFixedWindow;
	//报销面板
	var wipeFixedForm;
	//报销处理函数
	function wipeOutAssetInfo(){
		var record = grid.getSelectionModel().getSelected();
        if (!record) {
           Ext.MessageBox.alert('报销操作','请选择要报销的物品！');
        } else {

        	//设置报销设备ID
 			Ext.getCmp("fixedAssetId").setValue(record.get("fixedassetsid"));
           //报销窗口
			wipeFixedWindow=new Ext.Window({
			title:'报销设备',
			width:300,
			height:150,
			layout:'fit',
			closeAction:'hide',
			resizable:'false',
			//内嵌面板
			items:wipeFixedForm
			});
			//显示窗口
			wipeFixedWindow.show();
	}
	}

	//报销面板
	wipeFixedForm=new Ext.form.FormPanel({
	labelAlign:'right',
	buttonAlign:'center',
	frame:true,
	labelWidth:100,
	defaults:{
		width:120
	},
	//控件
	items:[
	{
		xtype:'hidden',
		id:'fixedAssetId',
		name:'fixedAssetId'
	},
	{
	height:20
	},
	{
		xtype:'textfield',
		fieldLabel:'报销数量',
		name:'wipeOutNumb',
		allowBlank:false
	}],
	buttons:[{
	text:'确认',
	handler:function(){
		//判断是否输入了数据
		if(wipeFixedForm.form.isValid()){
			wipeFixedForm.form.submit({
			url:'WipeOutAsset.jsj',
				success:function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					wipeFixedWindow.hide();
				},
				failure: function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					wipeFixedWindow.hide();
				},
				waitMsg:'正在发送请求，稍后...'
			})
		}else{
			Ext.Msg.alert('提示','请填写完成再提交！');
		}
	}
	},{
		text:'取消',
		handler:function(){
			wipeFixedWindow.hide();
		}
	}]
	})



	//查看资金情况窗口
	var lookAssetMoneyWin;
	//查看资金情况面板
	var lookAssetMoneyForm;
	function lookGoodsMoney(){
		//添加设备窗口
		lookAssetMoneyWin=new Ext.Window({
			title:'查看总资金情况',
			width:400,
			height:200,
			layout:'fit',
			closeAction:'hide',
			resizable:'false',
			//内嵌面板
			items:lookAssetMoneyForm
		});


        //显示窗口
		lookAssetMoneyWin.show();
		//发送请求加载数据
		lookAssetMoneyForm.getForm().load({
        url:'LookFixedAssetMoney.jsj',
       waitMsg : '正在载入数据...'
        });
	}

	//查看资金情况面板
	lookAssetMoneyForm=new Ext.form.FormPanel({
	labelAlign:'right',
	buttonAlign:'center',
	frame:true,
	labelWidth:100,
	defaults:{
		width:200
	},

	 reader: new Ext.data.JsonReader({root:'result'},
                                       [
                                       {name: 'totalmoney',mapping:'totalmoney',type:'int'},
                                       {name: 'wipeoutmoney',mapping:'wipeoutmoney',type:'int'},
                                       {name: 'leftmoney',mapping:'leftmoney',type:'int'}
                                      ]),

	//控件
	items:[
	{
	height:20
	},
	{
		xtype:'textfield',
		fieldLabel:'总资金',
		name:'totalmoney',
		allowBlank:true
	},
	{
		xtype:'textfield',
		fieldLabel:'报销资金',
		name:'wipeoutmoney',
		allowBlank:true
	},
	{
		xtype:'textfield',
		fieldLabel:'剩余总资金',
		name:'leftmoney',
		allowBlank:true
	}
	],
	buttons:[{
	text:'确认',
	handler:function(){
		lookAssetMoneyWin.hide();
	}
	}]
	})


		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});
		//创建选择模式对象
	var cb = new Ext.grid.CheckboxSelectionModel()
	//创建Grid表格组件
	var grid = new Ext.grid.GridPanel({
			renderTo : 'asset-detail-info',
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			trackMouseOver:true, //鼠标特效
			loadMask: true,    //是否显示正在加载
			store : store,
			height : 320,
			width : window.screen.width-220,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "固定资产ID",width: 100,  dataIndex: 'fixedassetsid', sortable: true},
				{header: "买进时间", width: 100,dataIndex: 'buytime', sortable: true},
				{header: "物品名",width: 150, dataIndex: 'goodsname', sortable: true},
				{header: "购买数量",width: 100, dataIndex: 'purchasenumber', sortable: true},
				{header: "金额",width: 100, dataIndex: 'goodsmoney', sortable: true},
				{header: "报销数量",width: 100, dataIndex: 'wipeoutnumber', sortable: true},
				{header: "备注",width: 150, dataIndex: 'goodsbrief', sortable: true}
				]
		});
})

</script>

</head>
<body>
<table>
	<tr>
		<td>
		<div id='searchExistAssetWin' style="margin: 8px 8px 4px 8px"></div>
		</td>
	</tr>
</table>
<div id='asset-detail-info' style="margin: 4px 8px 8px 8px"></div>
</body>
</html>